﻿var $pageSize = "12";
var $pageIndex = 0;
var $queryCondition = "";

$(document).ready(function () {
    $("#btnQuery").click(function () {
        var $fatherStr = "wlbm." + $("#txtMtrlCode").val();
        if ($("#selMtrlNo").val() == "-1") {
            $fatherStr = $("#selBig").val() + "." + $("#selSmall").val();
        }
        $queryCondition = $fatherStr;
        var $strParams = strList("selqCondition", $fatherStr);
        DataBind("MtrlInfoManage.aspx", $strParams, "dvWait", "正在为您查询数据，请稍候......", "dvShow", "dvPager", $pageSize, $pageIndex);
    });
});

$(document).ready(function () {
    $("#btnAdd").click(function () {
        location.href = "AddMtrlInfo.aspx";
    });
});


//页面加载时初始化下拉列表
$(document).ready(function () {
    var $fatherStr = "";
    var $type = "init";
    $.ajaxForPost("MtrlInfoManage.aspx/getSelInit",
                          "{ fatherStr:'" + $fatherStr + "',selType:'" + $type + "'}",
                          function () { },
                          function (data) {
                              $("#selBig").empty();
                              $("#selSmall").empty();
                              $("#selMtrlNo").empty();
                              var $jsondata = eval('(' + data.d + ')');
                              for (var i = 0; i < $jsondata.length; i++) {
                                  if (i == 0)
                                      $("#selBig").append($("<option selected='true'></option>").val($jsondata[i].value).html($jsondata[i].tvalue));
                                  else
                                      $("#selBig").append($("<option></option>").val($jsondata[i].value).html($jsondata[i].tvalue));
                              }
                              $("#selSmall").append($("<option selected='true'></option>").val("-2").html("--无--"));
                              $("#selMtrlNo").append($("<option selected='true'></option>").val("-2").html("--无--"));
                          });
    var $initqCondition = "all";
    $queryCondition = $initqCondition;
    var $strParams = strList("initqCondition", $initqCondition);
    DataBind("MtrlInfoManage.aspx", $strParams, "dvWait", "正在为您查询数据，请稍候......", "dvShow", "dvPager", $pageSize, $pageIndex);
});

$(document).ready(function () {
    $("#selBig").change(function () {
        var $fatherStr = $("#selBig").val();
        if ($("#selBig").val() == "-1") {
            $fatherStr = "all";
            $("#selSmall").empty();
            $("#selMtrlNo").empty();
            $("#selSmall").append($("<option selected='true'></option>").val("-2").html("--无--"));
            $("#selMtrlNo").append($("<option selected='true'></option>").val("-2").html("--无--"));
        }
        else {
            var $selType = "big";
            //获取相应小类信息
            $.ajaxForPost("MtrlInfoManage.aspx/getSelInit",
                          "{ fatherStr:'" + $fatherStr + "',selType:'" + $selType + "'}",
                          function () { },
                          function (data) {
                              $("#selSmall").empty();
                              $("#selMtrlNo").empty();
                              $("#selMtrlNo").append($("<option selected='true'></option>").val("-2").html("--无--"));
                              var $jsondata = eval('(' + data.d + ')');
                              if ($jsondata.length > 1) {
                                  for (var i = 0; i < $jsondata.length; i++) {
                                      if (i == 0)
                                          $("#selSmall").append($("<option selected='true'></option>").val($jsondata[i].value).html($jsondata[i].tvalue));
                                      else
                                          $("#selSmall").append($("<option></option>").val($jsondata[i].value).html($jsondata[i].tvalue));
                                  }
                              }
                              else {
                                  $("#selSmall").append($("<option selected='true'></option>").val("-2").html("--无--"));
                              }
                          });
        }
        $queryCondition = $fatherStr;
        var $strParams = strList("selqCondition", $fatherStr);
        DataBind("MtrlInfoManage.aspx", $strParams, "dvWait", "正在为您查询数据，请稍候......", "dvShow", "dvPager", $pageSize, $pageIndex);
    });
})

$(document).ready(function () {
    $("#selSmall").change(function () {
        var $fatherStr = "";
        $fatherStr = $("#selBig").val() + "." + $("#selSmall").val();
        if ($("#selSmall").val() == "-1") {
            $fatherStr = $("#selBig").val();
            $("#selMtrlNo").empty();
            $("#selMtrlNo").append($("<option selected='true'></option>").val("-2").html("--无--"));
        }
        else {
            var $selType = "small";
            //获取相应物料信息
            $.ajaxForPost("MtrlInfoManage.aspx/getSelInit",
                          "{ fatherStr:'" + $fatherStr + "',selType:'" + $selType + "'}",
                          function () { },
                          function (data) {
                              $("#selMtrlNo").empty();
                              var $jsondata = eval('(' + data.d + ')');
                              if ($jsondata.length > 1) {
                                  for (var i = 0; i < $jsondata.length; i++) {
                                      if (i == 0)
                                          $("#selMtrlNo").append($("<option selected='true'></option>").val($jsondata[i].value).html($jsondata[i].tvalue));
                                      else
                                          $("#selMtrlNo").append($("<option></option>").val($jsondata[i].value).html($jsondata[i].tvalue));
                                  }
                              }
                              else {
                                  $("#selMtrlNo").append($("<option selected='true'></option>").val("-2").html("--无--"));
                              }
                          });
        }
        $queryCondition = $fatherStr;
        var $strParams = strList("selqCondition", $fatherStr);
        DataBind("MtrlInfoManage.aspx", $strParams, "dvWait", "正在为您查询数据，请稍候......", "dvShow", "dvPager", $pageSize, $pageIndex);
    });
})

$(document).ready(function () {
    $("#selMtrlNo").change(function () {
        var $fatherStr = $("#selBig").val() + "." + $("#selSmall").val() + "." + $("#selMtrlNo").val();
        if ($("#selMtrlNo").val() == "-1") {
            $fatherStr = $("#selBig").val() + "." + $("#selSmall").val();
        }
        $queryCondition = $fatherStr;
        var $strParams = strList("selqCondition", $fatherStr);
        DataBind("MtrlInfoManage.aspx", $strParams, "dvWait", "正在为您查询数据，请稍候......", "dvShow", "dvPager", $pageSize, $pageIndex);
    });
})


function updateinfo(obj) {
    var $upValueStr = "";

    //获取组合值
    var $l1 = $(obj).parent().parent().find(".hid0").attr("value") + "/" + $(obj).parent().parent().find(".txtnoclickr0").val();
    var $l2 = $(obj).parent().parent().find(".hid1").attr("value") + "/" + $(obj).parent().parent().find(".txtnoclickr1").val();
    var $l3 = $(obj).parent().parent().find(".hid2").attr("value") + "/" + $(obj).parent().parent().find(".txtnoclickr2").val();
    var $l4 = $(obj).parent().parent().find(".hid3").attr("value") + "/" + $(obj).parent().parent().find(".txtnoclickr3").val();
    var $l5 = $(obj).parent().parent().find(".hid4").attr("value") + "/" + $(obj).parent().parent().find(".txtnoclickr4").val();

    if ($(obj).parent().parent().find(".hid3").attr("value") == "00")
        $(obj).parent().parent().find(".txtnoclickr3").val("");

    if ($(obj).parent().parent().find(".hid4").attr("value") == "00")
        $(obj).parent().parent().find(".txtnoclickr4").val("");

    $upValueStr = $l1 + "|" + $l2 + "|" + $l3 + "|" + $l4 + "|" + $l5;
    $.ajaxForPost("MtrlInfoManage.aspx/UpdateData",
                          "{ upValueStr:'" + $upValueStr + "'}",
                          function () { },
                          function (data) {
                              alert(data.d);
                          });
}

function deleteinfo(obj) {
    var $id = $(obj).attr("value");
    //获取组合值
    $.ajaxForPost("MtrlInfoManage.aspx/DeleteData",
                          "{ id:'" + $id + "'}",
                          function () { },
                          function (data) {
                              if (data.d == "0") {
                                  $(obj).parent().parent().hide();
                                  alert("删除成功！");
                              }
                              if (data.d == "1") {  
                                  $(obj).parent().parent().find(".txtnoclickr2").val("");
                                  $(obj).parent().parent().find(".txtnoclickr3").val("");
                                  $(obj).parent().parent().find(".txtnoclickr4").val("");
                                  alert("删除成功！");
                              }
                          });
}
